/**
 * @description: 配置8大作业票api信息
 * @param {type}
 * @return:
 */

// const map = new Map([
//   ['BigTicket', Function],
//   ['BlindPlatePlugging', Function],
//   ['ConfinedSpace', Function],
//   ['GroundBreaking', Function],
//   ['Height', Function],
//   ['HotWork', Function],
//   ['Lifting', Function],
//   ['OpenCircuit', Function],
//   ['TemporaryElectricity', Function]
// ])

const map = new Map()
// Dynamically import all configuration files from the config directory except index.js
const configFiles = import.meta.glob('./**/*.js', { eager: true })
for (const [key, module] of Object.entries(configFiles)) {
  if (!key.includes('index.js')) {
    const configModule = module.default
    const name = key.replace('./', '').replace('.js', '').split('/').pop()
    map.set(name, configModule)
  }
}

export default map

export function setApiConfig(key, config) {
  map.set(key, config)
}

export function getApiConfig(key) {
  return map.get(key)
}

export async function runApi(source, type, params, headers) {
  const res = await map.get(type)(source, params, headers)
  return res
}
